package com.sg.file.transform.provider.center;

import com.sg.file.common.conf.FileSizeTypeConf;
import com.sg.file.common.conf.VisibleFileSizeConf;
import com.sg.file.transform.api.dto.TransformReqeust;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.VideoAttributes;
import it.sauronsoftware.jave.VideoSize;

/**
 * 视频文件获取截图
 * Created by asus on 2018/7/17.
 */
public class VideoImageTrancode  extends FFmpegTranscode {
    @Override
    public EncodingAttributes getEncodeAttr(TransformReqeust transformReqeust) {
        //设置视频参数
        VideoAttributes video = new VideoAttributes();
        //如果为空则使用默认分辨率
        video.setSize(getVideoImageSize(transformReqeust));//-s width,height
        //设置转换器参数
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setDuration(0.01f);//-t
        attrs.setFormat("image2");//-f
        attrs.setVideoAttributes(video);

        return attrs;
    }

    /**
     * 根据文件尺寸类型，获取视频截图图片文件的尺寸
     * @param transformReqeust
     * @return
     */
    private VideoSize getVideoImageSize(TransformReqeust transformReqeust){
        VisibleFileSizeConf.Size size = VisibleFileSizeConf.getVoideSize(FileSizeTypeConf.THUMBNAIL);
        return new VideoSize(size.getWidth().intValue(),size.getHeight().intValue());
    }
}
